﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using QLab.IO.Files;

namespace QLab
{
  /// <summary>
  /// Interaction logic for frmTextInput.xaml
  /// </summary>
  public partial class frmTextInput : Window
  {
    protected const string _error_message =
@"Entered text cannot:
- contain any of the system characters
- contain Unicode control characters
- contain surrogate characters

Please enter a valid name.";

    protected string _inputText = String.Empty;

    public frmTextInput()
    {
      InitializeComponent();
    }

    public string InputText { get { return _inputText; } }

    public bool? ShowDialog(string FormTitle)
    {
      Title = FormTitle;
      return ShowDialog();
    }

    protected void ShowErrorMessage()
    {
      MessageBox.Show(_error_message, "QLab", MessageBoxButton.OK, MessageBoxImage.Exclamation);
    }

    private void btnOk_OnClick(object sender, RoutedEventArgs e)
    {
      string inputText = txtText.Text.Trim();

      if (!CustomFile.IsRegularFileName(inputText))
      {
        ShowErrorMessage();
        txtText.Focus();
        return;
      }

      _inputText = inputText;

      DialogResult = true;
    }

  }
}
